package composite.gk1;

import java.util.ArrayList;
import java.util.List;

public class LevelCource extends GkAbstractCource{
    private List<GkAbstractCource> courceList = new ArrayList<>();

    private String name;
    private int level;

    public LevelCource(String name, int level) {
        this.name = name;
        this.level = level;
    }

    @Override
    public void addChild(GkAbstractCource course) {
        courceList.add(course);
    }

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public void info() {
        System.out.println(this.toString());
        for (GkAbstractCource cource : courceList) {
            //该节点层级为几就打印几个·
            for (int i = 0; i < level; i++) {
                System.out.print("·");
            }

            cource.info();
        }
    }

    @Override
    public String toString() {
        return "LevelCource{" +
                "name='" + name + '\'' +
                ", level=" + level +
                '}';
    }
}
